package tt.dz.appserver.mvc.manage;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import tt.dz.appserver.entity.model.AppFeedBack;
import tt.dz.appserver.entity.model.ResultMappingEntity;
import tt.dz.appserver.service.business.AppFeedbackService;
import tt.dz.appserver.util.Result;
import tt.dz.appserver.util.enums.Response;

/**
 * 反馈管理
 * @author USER001
 *
 */
@RestController
@RequestMapping("/manage/appFeedBack")
public class AppFeedbackManager {

	/**App反馈管理**/
	@Resource
	AppFeedbackService appFeedbackService;
	
	/**
	 * App反馈删除
	 * @param userid		用户id
	 * @param createtime	生成时间	
	 **@param userphone		用户电话
	 **@param content		内容
	 **@param disposeflag	处理标志
	 **@param updatetime	更新时间
	 * @param operid		操作id
	 **@param validflag		有效标志
	 * @return
	 */
	@RequestMapping(value="/AppFeedbackDel",produces={"application/json;charset=utf-8"})
	public String appfeedbackdel(
		 	@RequestParam(value="userid") String userid,
		 	@RequestParam(value="createtime") String createtime,
			@RequestParam(value="operid") String operid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			
			//添加反馈
			JSONObject resultObject = appFeedbackService.appfeedbackdel(userid, createtime, operid);
			
			String code = resultObject.getString("code");
			String msg = resultObject.getString("msg");
			
			if (Response.SUCCESS.getCode().equals(code)) {
				//返回参数拼接（删除resultObject对象中的code和msg再返回）
				resultObject.remove("code");
				resultObject.remove("msg");
				
				resultMappingEntity = Result.responseBody(code, msg, resultObject);
			}
			else {
				resultMappingEntity = Result.responseBody(code, msg);
			}			
			
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}
	
	/**
	 * App反馈更新
	 * @param userid		用户id
	 * @param createtime	生成时间	
	 **@param userphone		用户电话
	 **@param content		内容
	 * @param disposeflag	处理标志
	 **@param updatetime	更新时间
	 * @param operid		操作id
	 **@param validflag		有效标志
	 * @return
	 */
	@RequestMapping(value="/AppFeedbackUpdate",produces={"application/json;charset=utf-8"})

	public String appfeedbackupdate(
		 	@RequestParam(value="userid") String userid,
		 	@RequestParam(value="createtime") String createtime,
			@RequestParam(value="disposeflag") Integer disposeflag,
			@RequestParam(value="operid") String operid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			//添加反馈
			JSONObject resultObject = appFeedbackService.appfeedbackupdate(userid, createtime, disposeflag, operid);
			
			String code = resultObject.getString("code");
			String msg = resultObject.getString("msg");
			
			if (Response.SUCCESS.getCode().equals(code)) {
				//返回参数拼接（删除resultObject对象中的code和msg再返回）
				resultObject.remove("code");
				resultObject.remove("msg");
				
				resultMappingEntity = Result.responseBody(code, msg, resultObject);
			}
			else {
				resultMappingEntity = Result.responseBody(code, msg);
			}			
			
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}	

	/**
	 * App反馈查询
	 **@param userid		用户id
	 **@param createtime	生成时间	
	 **@param userphone		用户电话
	 **@param content		内容
	 **@param disposeflag	处理标志
	 **@param updatetime	更新时间
	 **@param operid		操作id
	 **@param validflag		有效标志
	 * @return
	 */
	@RequestMapping(value="/AppFeedbackSelect",produces={"application/json;charset=utf-8"})

	public String appfeedbackselect() {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			//添加反馈
			List<AppFeedBack> resultObject = appFeedbackService.appfeedbackselect();
			
			String code = Response.SUCCESS.getCode();
			String msg = Response.SUCCESS.getMsg();
			
			resultMappingEntity = Result.responseBody(code, msg, resultObject);
						
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}	
		
}
